/**通用操作js文件**/

/**
 * 通用布局方法
 * @author       xiaogq
 * @param node
 */
function oper_layout(node){
    //获得实体名称
    var title = $(node).attr("title");
    //获取实体id
    var entityId = $(node).attr("tableCode");
    //获得操作按钮中文名称
    var buTitle = $(node).find("span[name='buTitle']").text();
    var url = "CommonOperation/fieldEmployeeLayout.do?position=List&isDefault=false&entityId="+entityId;
    //parent.addMenu(node,{title:title+":"+buTitle,url:url,type:"R"});
    var node = {id: "oper_layout"+entityId, text:title+":"+buTitle, url:url};
    //打开tabls标签
    parent.showTab(node);
}

/**
 * 通用过滤条件方法
 * @author       xiaogq
 * @param node
 */
function oper_filter(node){
    //获得实体名称
    var title = $(node).attr("title");
    //获取实体id
    var entityId = $(node).attr("tableCode");
    //获得操作按钮中文名称
    var buTitle = $(node).find("span[name='buTitle']").text();
    var url = "CommonOperation/fieldEmployeeLayout.do?position=Filter&isDefault=false&entityId="+entityId;
    //打开tabls标签
    //parent.addMenu(node,{title:title+":"+buTitle,url:url,type:"R"});
    var node = {id: "oper_filter"+entityId, text:title+":"+buTitle, url:url};
    //打开tabls标签
    parent.showTab(node);
}

/**
 * 通用的添加方法
 * @param node
 */
function oper_add(node){
    var title = $(node).attr("title");
    var entityId = $(node).attr("tableCode");
    var url = "CommonOperation/customAddInit.do?entityId="+entityId;
    //parent.addMenu(node,{title:title,url:url,type:"R"});
    var node = {id: "oper_add"+entityId, text:title, url:url};
    //打开tabls标签
    parent.showTab(node);
}

/**
 * 通用的查看详情方法
 * @param node
 */
function fun_view(node){
    var id = $(node).attr("id");
    var title = $(node).attr("title");
    var rowName = $(node).attr("name");
    var entityId = $(node).attr("tableCode");
    var url = "CommonOperation/customView.do?entityId="+entityId +"&id="+ id+"&rowName="+rowName;
    //parent.addMenu(node,{title:title,url:url,type:"R"});
    var node = {id: "fun_view"+entityId, text:title, url:url};
    //打开tabls标签
    parent.showTab(node);
}

/**
 * 通用的更新方法
 * @param node
 */
function fun_update(node){
    var id = $(node).attr("id");
    var title = $(node).attr("title");
    var entityId = $(node).attr("tableCode");
    var url = "CommonOperation/customEditInit.do?entityId="+entityId +"&id="+ id;
    var node = {id: "fun_update"+entityId, text:title, url:url};
    //打开tabls标签
    parent.showTab(node);
}

/**
 * 通用的删除方法
 * @param node
 */
function fun_delete(node){
    //获取当前记录id
    var id = $(node).attr("id");
    var entityId = $(node).attr("tableCode");
    var url = "CommonOperation/customDelete.do";
    //获取删除按钮的位置(showList:列表上，showColumn：列前，showView：详情页上)
    var showHere = $(node).attr("showHere");
    if(confirm("确定要删除该条数据吗？")){
        $.ajax({
            type: 'POST',
            contentType: 'application/json',
            url: getRootPath()+"/"+ url +"?id="+id +"&entityId="+ entityId,
            dataType: 'json',
            success: function(data) {
                var flag = data.flag;
                if(flag != "true"){
                    alert(flag);
                }else{
                    if(showHere == "showColumn"){
                        $("#bootstrapTable").bootstrapTable("refresh", {query:{}});
                    }else if(showHere == "showView"){
                        parent.closeTab(1);
                    }
                }
            },
            error: function(data) {
                alert("删除数据发生错误!");
            }
        });
    }
}

/**
 * 启用数据方法
 * @param node
 */
function fun_enable(node) {
    //获取当前记录id
    var id = $(node).attr("id");
    var entityId = $(node).attr("tableCode");
    var url = $(node).attr("url");
    if(confirm("确定要启用该条数据吗？")){
        $.ajax({
            type: 'POST',
            contentType: 'application/json',
            url: getRootPath()+"/"+ url +"?id="+id +"&entityId="+ entityId,
            dataType: 'json',
            success: function(data) {
                $("#bootstrapTable").bootstrapTable("refresh", {query:{}});
            },
            error: function(data) {
                alert("启用数据发生错误!");
            }
        });
    }
}

/**
 * 停用数据方法
 * @param node
 */
function fun_disable(node) {
    var id = $(node).attr("id");
    var entityId = $(node).attr("tableCode");
    var url = $(node).attr("url");
    if(confirm("确定要停用该条数据吗？")){
        $.ajax({
            type: 'POST',
            contentType: 'application/json',
            url: getRootPath()+"/"+ url +"?id="+id +"&entityId="+ entityId,
            dataType: 'json',
            success: function(data) {
                $("#bootstrapTable").bootstrapTable("refresh", {query:{}});
            },
            error: function(data) {
                alert("停用数据发生错误!");
            }
        });
    }
}